//
//  HcollectTableViewCell.swift
//  旅航ios
//
//  Created by tulip on 2021/4/25.
//

import UIKit
import SwiftyJSON

class HcollectTableViewCell: UITableViewCell,UICollectionViewDelegate,UICollectionViewDataSource {
    var data:[JSON]=[]
    @IBOutlet weak var collect: UICollectionView!
    override func awakeFromNib() {
        super.awakeFromNib()
    let layout=UICollectionViewFlowLayout.init()
    layout.itemSize=CGSize(width: SCREEN_WIDTH-40, height: 83)
    layout.scrollDirection = .horizontal
    layout.sectionInset=UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    layout.minimumLineSpacing=0
    layout.minimumInteritemSpacing=5
    collect.backgroundColor=UIColor.clear
    collect.collectionViewLayout=layout
    collect.contentOffset=CGPoint(x: SCREEN_WIDTH+20, y: 0)
    collect.delegate=self
    collect.dataSource=self
    collect.isPagingEnabled=true
    collect.showsHorizontalScrollIndicator=false
    collect.register(UINib(nibName: "HengCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "HengCollectionViewCell")
   
        collect.layer.masksToBounds=false
       
   
        Network.request(.home) { (JSON) in
            self.data=JSON["data"]["bannernew"].array ?? []
            self.collect.reloadData()
        } failure: { (err) in
            
        }


}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
    
    self.selectionStyle = .none
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    data.count
}
    
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    
}
    
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell:HengCollectionViewCell=collectionView.dequeueReusableCell(withReuseIdentifier: "HengCollectionViewCell", for: indexPath) as! HengCollectionViewCell
    let url=data[indexPath.row]["img"].string ?? ""
    cell.img.kf.setImage(with: URL(string: url))
    return cell
}



}
